package com.linkgie.galaxyframework.crypto.context;

import java.io.InputStream;
import java.io.OutputStream;

import com.linkgie.galaxyframework.crypto.AsymmetricStreamingCipherService;
import com.linkgie.galaxyframework.crypto.PrivateKey;
import com.linkgie.galaxyframework.crypto.PublicKey;
import com.linkgie.galaxyframework.crypto.spi.AsymmetricStreamingCipherFuncSPI;
import com.linkgie.galaxyframework.crypto.spi.PrivateKeybytes;
import com.linkgie.galaxyframework.crypto.spi.PublicKeybytes;

public class AsymmetricStreamingCipherServiceImpl extends AsymmetricCipherServiceImpl
		implements AsymmetricStreamingCipherService {
	
	private final AsymmetricStreamingCipherFuncSPI STREAMING_CIPHER_SPI;
	
	public AsymmetricStreamingCipherServiceImpl(AsymmetricStreamingCipherFuncSPI innerService) {
		super(innerService);
		
		STREAMING_CIPHER_SPI = (AsymmetricStreamingCipherFuncSPI) innerService;
	}

	@Override
	public int encrypt(PublicKey key, InputStream in, OutputStream out) {
		PublicKeybytes pubKeyBytes = ENCODING.decode(key);
		return STREAMING_CIPHER_SPI.encrypt(pubKeyBytes, in, out);
	}

	@Override
	public int encrypt(byte[] rawKey, InputStream in, OutputStream out) {
		return STREAMING_CIPHER_SPI.encrypt(rawKey, in, out);
	}

	@Override
	public int decrypt(PrivateKey key, InputStream in, OutputStream out) {
		PrivateKeybytes privKeyBytes = ENCODING.decode(key);
		return STREAMING_CIPHER_SPI.decrypt(privKeyBytes, in, out);
	}

	@Override
	public int decrypt(byte[] rawKey, InputStream in, OutputStream out) {
		return STREAMING_CIPHER_SPI.decrypt(rawKey, in, out);
	}
	

}
